﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SwParaPlatform2.dlgUIConfig
{
    public partial class PreviewForm : Form
    {
        private PictureBox pictureBox;
        private float zoomFactor = 1.0f;

        public PreviewForm(Image image)
        {
            this.pictureBox = new PictureBox
            {
                Image = image,
                SizeMode = PictureBoxSizeMode.Zoom,  // 设置预览图片的SizeMode为Zoom
                Dock = DockStyle.Fill  // 填充整个窗口
            };

            this.Controls.Add(pictureBox);
            this.MouseWheel += PreviewForm_MouseWheel;  // 添加鼠标滚轮事件
            this.Click += PreviewForm_Click;  // 添加点击事件
        }

        private void PreviewForm_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta > 0)
                zoomFactor *= 1.1f;  // 放大
            else
                zoomFactor /= 1.1f;  // 缩小

            // 根据缩放因子调整PictureBox的大小
            pictureBox.Size = new Size((int)(this.ClientSize.Width * zoomFactor), (int)(this.ClientSize.Height * zoomFactor));
            pictureBox.Location = new Point((this.ClientSize.Width - pictureBox.Width) / 2, (this.ClientSize.Height - pictureBox.Height) / 2);
        }

        private void PreviewForm_Click(object sender, EventArgs e)
        {
            this.Close();  // 点击空白处关闭窗口
        }
    }
}
